<h2><a href="<?=site_url('company/'.$company->company_name);?>"><?=$company->company_name;?></a> &ndash; <a href="<?=site_url('jobs/showUpdates/'.$job->id);?>"><?=$job->job_title;?></a></h2>

<div class="block">
	<div class="hd">
		<ul>
			<li><a href="<?=site_url('company/'.$company->company_name.'/'.$job->job_title.'/update');?>">Updates</a></li>
			<li><a href="<?=site_url('company/'.$company->company_name.'/'.$job->job_title.'/schedule');?>">Schedule</a></li>
			<li><a href="<?=site_url('company/'.$company->company_name.'/'.$job->job_title.'/setup');?>">Job Information</a></li>
			<li><a href="<?=site_url('company/'.$company->company_name.'/'.$job->job_title.'/billing');?>">Billing</a></li>
			<li><a href="<?=site_url('company/'.$company->company_name.'/'.$job->job_title.'/users');?>">User Assignment</a></li>
		</ul>
		<div class="clear"></div>
	</div>
	<div class="bd">



	<p class="totalTime"><span>Progress:</span> <?php if ($totaltime > 0 && $allocatedtime > 0) echo number_format(($totaltime / $allocatedtime )*100, 0).'%'; else echo '--';?> <?php if ($permissions->showtime):?><span>Allocated:</span> <?=$allocatedtime;?>hrs <span>Spent:</span> <?=$totaltime;?>hrs <span class="right">Yours:</span> <?=$usertime;?>hrs<?php endif;?></p>

<div class="invoiceDetails">
	<p><strong><?=$invoice->invoicetitle;?> [<?=$invoice->reference;?>]</strong></p>
	
	<p>FAO: <?php if (!$invoice->attentionofid) echo $invoice->attentionof_text; else if ($invoice->attentionof) echo $invoice->attentionof->firstname . ' ' . $invoice->attentionof->surname?></p>

	<p><?=$company->company_name;?><br />
	<?php if (!$invoice->addressid) echo nl2br($invoice->address_text); else if ($invoice->address): ?>
		<?php if ($invoice->address->address1) : ?><?=$invoice->address->address1;?><br /><?php endif;?>
		<?php if ($invoice->address->address2) : ?><?=$invoice->address->address2;?><br /><?php endif;?>
		<?php if ($invoice->address->city) : ?><?=$invoice->address->city;?><br /><?php endif;?>
		<?php if ($invoice->address->region) : ?><?=$invoice->address->region;?><br /><?php endif;?>
		<?php if ($invoice->address->postcode) : ?><?=$invoice->address->postcode;?><br /><?php endif;?>
	<?php endif;?></p>
</div>

<div class="invoiceDetailsLeft">
	<?php if($invoice->reference):?><p>Invoice Ref: <strong><?=$invoice->reference;?></strong></p><?php endif;?>	
	<?php if($job->ponumber):?><p>PO Number: <strong><?=$job->ponumber;?></strong></p><?php endif;?>
	<?php if($invoice->datecreated):?><p>Issue Date: <strong><?=date('d/m/Y', strtotime($invoice->datecreated));?></strong></p><?php endif;?>
	<?php if($invoice->duedate):?><p>Due Date: <strong><?=date('d/m/Y', strtotime($invoice->duedate));?></strong></p><?php endif;?>
</div>

<p style="clear:both;"><?=$invoice->description;?></p>

<table width="100%" class="viewInvoice" cellspacing="0">
	<thead>
		<tr bgcolor="#000000">
			<th bgcolor="#000000" class="department">Department</th><th bgcolor="#000000" class="description">Description</th><th bgcolor="#000000" class="cost numberfield">Cost (&pound;)</th>
		</tr>
	</thead>

	<tbody>
	<?php foreach ($invoice->lines as $key => $line):?>
		<tr>
			<td class="department"><?=$line->department;?></td>
			<td><?=$line->description;?></td>
			<td class="numberfield"><?=$line->cost;?></td>
		</tr>
	<?php endforeach;?>
	</tbody>
</table>

<p class="total">Total (&pound;) <span class="total"><?=$invoice->total_cost;?></span></p>

</div>



<div class="sidecolumn">
	<h2>Invoice Status</h2>
	<?php if (!$invoice->cancelled):?>
	
		<p><?php if ($invoice->processed):?>
			Invoiced on <?=date('d/m/Y', strtotime($invoice->processeddate));?><br />
			<a href="<?=site_url('jobs/markInvoiceUnprocessed/'.$invoice->id);?>">Mark as unprocessed</a>
			<?php else:?>
				This invoice has not been sent to the client yet.<br />
			<a href="<?=site_url('jobs/markInvoiceProcessed/'.$invoice->id);?>">Mark as processed</a>
			<?php endif;?></p>
		
		
		
		<p><?php if ($invoice->paid):?>Paid on <?=date('d/m/Y', strtotime($invoice->paiddate));?><br />
			<a href="<?=site_url('jobs/markInvoiceUnpaid/'.$invoice->id);?>">Mark as unpaid</a>
		<?php else:?>
			This invoice has not been paid by the client yet.<br />
			 <a href="<?=site_url('jobs/markInvoicePaid/'.$invoice->id);?>">Mark as paid</a>
		<?php endif;?></p>


			<p><br /><a href="<?=site_url('jobs/markInvoiceCancelled/'.$invoice->id);?>">Cancel this Invoice</a></p>
	
	<?php else:?>
		<p>This invoice was cancelled.</p>
	<?php endif;?>
		
</div>
<div class="sidecolumn">
	<h2>Invoice Notes</h2>
	<p class="edit_textarea" id="<?=$invoice->id;?>|invoice|notes"><?=$invoice->notes;?></p>
</div>

	<?php if ($otherinvoices):?>
<div class="sidecolumn">
	<h2>Other Job Invoices</h2>
	
	<ul>
	<?php foreach($otherinvoices as $invoice):?>
		<li><a href="<?=site_url('jobs/viewinvoice/'.$invoice->id);?>"><?=$invoice->invoicetitle;?></a> <strong>&pound;<?=number_format($invoice->total_cost, 2);?></strong><br /><?php if ($invoice->paid) echo 'Paid'; else echo 'Outstanding - Due '.date('d/m/y', strtotime($invoice->duedate));?></li>
	<?php endforeach;?>
	</ul>
	</div>
	<?php endif;?>
	
